package cn.com.cifi.mars.common.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 *
 * @author: user
 * @date: ${DATE} ${TIME}
 */
@ApiModel(value = "ReturnObject", description = "响应体")
@Data
@NoArgsConstructor
public class R<T> implements Serializable {

    private static final long serialVersionUID = 101539585470879542L;

    public static final int CODE_SUCCESS = 1;
    public static final int CODE_FAIL = 0;
    public static final int CODE_NOT_LOGIN = -1;
    public static final String MSG_SUCCESS = "操作成功";
    public static final String MSG_FAIL = "操作失败";
    public static final String MSG_NOT_LOGIN = "没有登录";

    @ApiModelProperty(value = "响应数据")
    private T data;

    @ApiModelProperty(value = "响应编码")
    private int code;

    @ApiModelProperty(value = "响应信息")
    private String message;

    public R(Boolean b) {
        if (!b) {
            this.code = CODE_FAIL;
            this.message = MSG_FAIL;
        } else {
            this.code = CODE_SUCCESS;
            this.message = MSG_SUCCESS;
        }
    }

    public R(T data) {
        super();
        this.code = CODE_SUCCESS;
        this.message = MSG_SUCCESS;
        this.data = data;
    }

    public R(Boolean b, T data) {
        if (!b) {
            this.code = CODE_FAIL;
            this.message = MSG_FAIL;
        } else {
            this.code = CODE_SUCCESS;
            this.message = MSG_SUCCESS;
        }
        this.data = data;
    }

    public R(int code, String msg) {
        super();
        this.code = code;
        this.message = msg;
    }

    public R(int code, String msg, String errorMsg) {
        super();
        this.code = code;
        this.message = msg;
    }

    public R(int code, String msg, T data) {
        super();
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    public R(int code, String msg, String errorMsg, T data) {
        super();
        this.code = code;
        this.message = msg;
        this.data = data;
    }

}